package com.prime.common.util;



import com.prime.common.constants.ApiConstants;

import java.util.Map;

/**
 * Created by cph on 17/2/8.
 */
public class Utils {

    private static final int BUFFER_SIZE = 1024;

    /**
     * 判断传入的参数是否缺少
     *
     * @param keys
     * @param params
     * @return
     */
    public static String isHaveParamValue(String[] keys, Map<String, Object> params) {
        for (String key : keys) {
            if (!params.containsKey(key) || "".equals(params.get(key))) {
                return "参数" + key + "不能为空！";
            }
        }
        return "";
    }

    //新增结果返回
    public static String addReturn(int result) {
        if (0 < result) {
            return JacksonUtil.toBizJson(ApiConstants.SUCCESS, ApiConstants.ADD_S_MSG, null);
        } else {
            return JacksonUtil.toBizJson(ApiConstants.ERROR, ApiConstants.ADD_F_MSG, null);
        }
    }

    //新增结果返回
    public static String deleteReturn(int result) {
        if (0 < result) {
            return JacksonUtil.toBizJson(ApiConstants.SUCCESS, ApiConstants.DEL_S_MSG, null);
        } else {
            return JacksonUtil.toBizJson(ApiConstants.ERROR, ApiConstants.DEL_F_MSG, null);
        }
    }

    //更新结果返回
    public static String updateReturn(int result) {
        if (0 < result) {
            return JacksonUtil.toBizJson(ApiConstants.SUCCESS, ApiConstants.UPDATE_S_MSG, null);
        } else {
            return JacksonUtil.toBizJson(ApiConstants.ERROR, ApiConstants.UPDATE_F_MSG, null);
        }
    }


    //更新结果返回
    public static String findReturn(Object result) {
        return JacksonUtil.toBizJson(ApiConstants.SUCCESS, ApiConstants.GET_S_MSG, result);
    }

}
